package cn.sh.yhk.mapper.basic;

import cn.sh.yhk.model.basic.SRole;
import cn.sh.yhk.model.basic.SRoleExample;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;

import java.util.List;

@Mapper
public interface SRoleMapper {
    @SelectProvider(type = SRoleSqlProvider.class, method = "countByExample")
    long countByExample(SRoleExample example);

    @DeleteProvider(type = SRoleSqlProvider.class, method = "deleteByExample")
    int deleteByExample(SRoleExample example);

    @Insert({
            "insert into s_role (id, role_name, ",
            "group, theme_ids, ",
            "remark, activity, ",
            "create_account, create_timestamp, ",
            "modify_account, modify_timestamp, ",
            "site)",
            "values (#{id,jdbcType=INTEGER}, #{groupName,jdbcType=VARCHAR}, ",
            "#{group,jdbcType=VARCHAR}, #{themeIds,jdbcType=VARCHAR}, ",
            "#{remark,jdbcType=VARCHAR}, #{activity,jdbcType=VARCHAR}, ",
            "#{createAccount,jdbcType=VARCHAR}, #{createTimestamp,jdbcType=BIGINT}, ",
            "#{modifyAccount,jdbcType=VARCHAR}, #{modifyTimestamp,jdbcType=BIGINT}, ",
            "#{site,jdbcType=VARCHAR})"
    })
    int insert(SRole record);

    @InsertProvider(type = SRoleSqlProvider.class, method = "insertSelective")
    int insertSelective(SRole record);

    @SelectProvider(type = SRoleSqlProvider.class, method = "selectByExample")
    @Results(id = "SRoleMap", value = {
            @Result(column = "id", property = "id", jdbcType = JdbcType.INTEGER),
            @Result(column = "role_name", property = "roleName", jdbcType = JdbcType.VARCHAR),
            @Result(column = "role", property = "role", jdbcType = JdbcType.VARCHAR),
            @Result(column = "theme_ids", property = "themeIds", jdbcType = JdbcType.VARCHAR),
            @Result(column = "remark", property = "remark", jdbcType = JdbcType.VARCHAR),
            @Result(column = "activity", property = "activity", jdbcType = JdbcType.VARCHAR),
            @Result(column = "create_account", property = "createAccount", jdbcType = JdbcType.VARCHAR),
            @Result(column = "create_timestamp", property = "createTimestamp", jdbcType = JdbcType.BIGINT),
            @Result(column = "modify_account", property = "modifyAccount", jdbcType = JdbcType.VARCHAR),
            @Result(column = "modify_timestamp", property = "modifyTimestamp", jdbcType = JdbcType.BIGINT),
            @Result(column = "site", property = "site", jdbcType = JdbcType.VARCHAR)
    })
    List<SRole> selectByExample(SRoleExample example);

    @UpdateProvider(type = SRoleSqlProvider.class, method = "updateByExampleSelective")
    int updateByExampleSelective(@Param("record") SRole record, @Param("example") SRoleExample example);

    @UpdateProvider(type = SRoleSqlProvider.class, method = "updateByExample")
    int updateByExample(@Param("record") SRole record, @Param("example") SRoleExample example);

    @Select("select * from s_role where id in (select user_id from s_user_role where user_id=#{userId})")
    @ResultMap(value = "SRoleMap")
    List<SRole> selectRoleByUserId(Long userId);
}